package com.lintf.devdemo.controller;

import com.lintf.devdemo.common.Result;
import com.lintf.devdemo.service.ISysFileInfoService;
import com.lintf.devdemo.service.ISysImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;



/**
 * @ system:Window
 * @ author:lin tingfeng
 * @ data:2022/10/19-14:10
 * @ package_name:com.lintf.devdemo.controller
 * @ project_name:DevDemo
 * @ desc:系统文件控制层
 */
@Api(value = "系统文件处理API")
@RestController
@RequestMapping("/sysFileInfo")
public class ISysFileInfoController {

    @Autowired
    private ISysFileInfoService iSysFileInfoService;

    @Autowired
    private ISysImageService iSysImageService;

    @ApiOperation(value = "上传头像图片")
    @PostMapping("/uploadHeadImage")
    public Result uploadHeadImage(MultipartHttpServletRequest file) throws Exception {
        if (null == file) {
            throw new Exception("文件不能为空！");
        }
        return iSysImageService.uploadHeadImage(file);
    }

    @ApiOperation(value = "根据图片Id获取图片流")
    @GetMapping("/showImgStream")
    public Result showImgStream(String id) throws Exception {
        if (id == null && id.equals("")){
            throw new Exception("文件id不能为空！");
        }
        return Result.success(iSysImageService.showImgStream(id));
    }

    @ApiOperation(value = "获取上传文件列表")
    @GetMapping("/uploadFileList")
    public Result uploadFileList(){
        return Result.success(iSysFileInfoService.uploadFileList());
    }

}
